import gameNetWorkState from "./SdkTools/gameNetWorkState";
import gameShareAdsVideo from "./SdkTools/gameShareAdsVideo";
import storage from "./SdkTools/storage";
import TipsManager from "./SdkTools/TipsManager";
import TopUi from "./TopUi";

/**
 * 在线奖励
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class addGold extends cc.Component {

    @property(cc.Label)
    cishu:cc.Label = null

    @property(cc.Node)
    kuang:cc.Node = null

    @property(cc.Node)
    closenode:cc.Node = null

    private topuisc:TopUi = null

    onLoad () {
        this.showUi()
        this.cishu.string = '' + storage.Instance.addgoldcishu
    }

    protected onEnable(): void {
        gameShareAdsVideo.Instance.bannerAds_Show()
        gameShareAdsVideo.Instance.chaPingAds_Show()

        if(gameNetWorkState.Instance.getOpenState_Video()){
            cc.find('ling', this.kuang).active = !1
            cc.find('shuang', this.kuang).active = !0
        }else{
            cc.find('ling', this.kuang).active = !0
            cc.find('shuang', this.kuang).active = !1
        }
    }

    protected onDisable(): void {
        gameShareAdsVideo.Instance.bannerAds_Hide()
    }

    start () {

    }

    showUi(){
        this.kuang.scale = 0.3
        cc.tween(this.kuang)
        .to(0.1,{scale:1})
        .start()

        var self = this
        this.closenode.active = !1
        cc.tween(this.closenode)
        .delay(2)
        .call(()=>{
            self.closenode.active = !0
        })
        .start()
    }

    setTopUiSc(){
        let sc = cc.find('Canvas/top').getComponent(TopUi)
        if(sc){
            this.topuisc = sc
        }
        // let over = cc.find('Canvas/GameOver/top')
        // if(over){
        //     let sc2 = over.getComponent(TopUi)
        //     if(sc2){
        //         this.topuisc = sc2
        //     }
        // }
        
    }

    addBtnClick(){
        if(storage.Instance.addgoldcishu > 0){
            let self = this
            gameShareAdsVideo.Instance.motivational_Video_Show(()=>{
                storage.Instance.addgoldcishu --
                self.cishu.string = '' + storage.Instance.addgoldcishu
                storage.Instance.setGold(storage.Instance.getGold()+100)
                if(self.topuisc){
                    self.topuisc.setGold()
                }
                self.closeBtnClick()
            }, ()=>{})
        }else{
            TipsManager.Instance.createTips('当前次数已用尽！')
        }
    }

    addBtnClick2(){
        if(storage.Instance.addgoldcishu > 0){
            let self = this
            gameShareAdsVideo.Instance.motivational_Video_Show(()=>{
                storage.Instance.addgoldcishu --
                self.cishu.string = '' + storage.Instance.addgoldcishu
                storage.Instance.setGold(storage.Instance.getGold()+200)
                if(self.topuisc){
                    self.topuisc.setGold()
                }
                self.closeBtnClick()
            }, ()=>{})
        }else{
            TipsManager.Instance.createTips('当前次数已用尽！')
        }
    }

    closeBtnClick(){
        this.node.destroy()
    }


    // update (dt) {}
}
